﻿@model IEnumerable<MembershipUser> 
@using res = Resource.Views.Admin.Admin;
@{YQBlog.General.GeneralConfigInfo ci = ViewBag.CI as YQBlog.General.GeneralConfigInfo;}
@section Css{
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.all.input.css")" rel="stylesheet" type="text/css" />
}
@section MenuInfo{
<ul> 
    <li class="selected">
        <span class="selected-arrow">&nbsp;</span>
        @Html.ActionLink("-"+ res.ManagementHome+" -", "Index", "Admin")
        <ul style="width:400px;">
            <li>@Html.ActionLink(res.Home, "Index", "Admin")</li>
            <li class="selected">@Html.ActionLink(res.Generatepages, "AdminHtmlCreate", "Admin")</li>
        </ul>
    </li>
    <li>@Html.ActionLink("-" + res.ContentManagement + " -", "AdminArticle", "Admin", new { tid = 1 }, null)</li>
    <li>@Html.ActionLink("-" + res.Configuration + " -", "AdminBaseConfig", "Admin")</li>
    <li>@Html.ActionLink("-" + res.UserManagement + " -", "AdminUserList", "Admin")</li>
</ul>
}

<div id="mainContent">
        <div id="leftBox">
          <div class="contentBox">
            <div class="contentBoxTop">
              <h3>@res.Generatepages</h3>
            </div>
            <div class="innerContent">
                @res.Language：
                @Html.DropDownList("LangList")
                @res.Category：
                @Html.DropDownList("CateId")
                @res.Date：
                <select name="SelDateRange" id="SelDateRange">
                <option value="0" selected="selected">@res.Nolimited</option>
                <option value="1">@res.Range</option>
                </select>
                <span id="rangeInfo" style="display:none;">
                From:
                <input type="text" value="@DateTime.Now.ToString("MM/dd/yyyy")" name="rangeStart" id="rangeStart" style="width:80px;">
                To:
                <input type="text" value="@DateTime.Now.ToString("MM/dd/yyyy")" name="rangeEnd" id="rangeEnd" style="width:80px;">
                </span>
                <div class="add">
                <a href="###" onclick="BatchCreate();">@res.Create</a>
                </div>

                <div class="scheduleBg"><div class="schedule"></div></div> <div class="scheduleStat"><span id="currentcount"></span><span id="maxcount"></span></div>
            </div>
          </div>
      </div>
  </div>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
@if (Resource.Models.Web.Web.Lang == "" || Resource.Models.Web.Web.Lang == "zh-tw")
{ 
    <script src="@Url.Content("~/Scripts/jquery.ui.datepicker-zh-CN.js")" type="text/javascript"></script>
}
<script type="text/javascript">
    var d = null;
    var i = 0;
    var langLength = $('#LangList option').length;
    var langIndex = 1;
    var langValue = "";
    var max = 0;
    var current = 0;
    $(function () {
        $("#rangeStart").datepicker(
        {
            changeMonth: true,
            changeYear: true
        });
        $("#rangeEnd").datepicker(
        {
            changeMonth: true,
            changeYear: true
        });

        $('#SelDateRange').change(function () {
            if ($('#SelDateRange').val() == "0")
            { $('#rangeInfo').hide(); }
            else
            { $('#rangeInfo').show(); }
        });
    });

    function BatchCreate() {
        var d1 = new Date($('#rangeStart').val());
        var d2 = new Date($('#rangeEnd').val());
        if ($('#SelDateRange').val() == "1" && d1 > d2) {
            alert("@res.DateCompare");
            return;
        }
        $.post('/Admin/AdminHtmlBatchCreate', { cate: $('#CateId').val(), dateRange: $('#SelDateRange').val(), from: $('#rangeStart').val(), to: $('#rangeEnd').val(), rn: Math.random() }, function (data) {
            d = eval(data);
            i = 0;
            langIndex = 1;
            langValue = $('#LangList').val();
            current = 0;
            if (d.length > 0) {
                BatchCreateExec();
            }
            else {
                $('#currentcount').html("0");
                $('#maxcount').html(" / 0");
                $('.schedule').css({ "width": "0%" });
            }
        });
    }

    function BatchCreateExec() {
        if (langValue != "") {
            max = d.length;
            DoCreate();
        }
        else {
            max = d.length * (langLength-1);
            DoCreateByLang();
        }
        $('#maxcount').html(" / "+max);
        $('#currentcount').html(current);
    }

    function DoCreate() {
        $.post('/Admin/AdminDoCreate', { date: d[i]["date"], lang: langValue, id: d[i]["id"], rename: d[i]["rename"], rn: Math.random() }, function (re) {
            i++;
            SetSchedule();
            if (i < d.length) {
                DoCreate();
            }
        });
    }

    function DoCreateByLang() {
        $.post('/Admin/AdminDoCreate', { date: d[i]["date"], lang: $('#LangList option:eq(' + langIndex + ')').val(), id: d[i]["id"], rename: d[i]["rename"], rn: Math.random() }, function (re) {
            langIndex++;
            SetSchedule();
            if (langIndex < langLength) {
                DoCreateByLang();
            }
            else {
                langIndex = 1;
                i++;
                if (i < d.length) {
                    DoCreateByLang();
                }
            }
        });
    }

    function SetSchedule() {
        $('#currentcount').html(++current);
        $('.schedule').css({ "width": current*100/max+"%" });
    }
</script>